function chooseAll(check) {
	var chooseAll = document.getElementsByName("selected_id");
	if(null == chooseAll) return;
	var len = chooseAll.length;
	for(var i = 0; i < len; i++){
		var element = chooseAll[i];
      if(element.type == 'checkbox') {
			element.checked = check.checked?true:false;
		}
	}
}

function chooseElse(check) {
	var chooseAll = document.getElementsByName("selected_id_1");
	if(null == chooseAll) return;
	var len = chooseAll.length;
	for(var i = 0; i < len; i++){
		var element = chooseAll[i];
      if(element.type == 'checkbox') {
			element.checked = check.checked?true:false;
		}
	}
} 
function chooseOther(check) {
	var chooseAll = document.getElementsByName("selected_id_2");
	if(null == chooseAll) return;
	var len = chooseAll.length;
	for(var i = 0; i < len; i++){
		var element = chooseAll[i];
      if(element.type == 'checkbox') {
			element.checked = check.checked?true:false;
		}
	}
} 

//create by kellen
function formSubmit(theform,url,_msg){  
	//alert("url>>"+url);
	if(null!=_msg) {
		if(confirm(_msg)){
			if(null!=url||url!=""){
				theform.action=url;
			}
			theform.submit();
		}else return false;
	}else{
		if(null!=url||url!=""){
			theform.action=url;
		}
		theform.submit();
	}
}
//open new windows
function MM_openBrWindow(theURL,winName,features) { //v2.0
	var width = 800;
	var height = 600;
	var aryw=features.split('width=')
 	var aryh=features.split('height=')
	if(aryw.length>1) 
	  width=parseInt(aryw[1])
	if(aryh.length>1) 
	  height=parseInt(aryh[1])
		 
	var pos = ",left=" + parseInt((screen.availWidth - width) / 2) + "," +
    "top=" + parseInt((screen.availHeight - height) / 2);
  	features = features+pos;
	if(-1 != theURL.indexOf("?")){
		theURL = theURL+"&referer=auto";
	}
  	window.open(theURL,winName,features);
}
//-->
/*
//skip to windows
function winSkip(url,_target,_class){ 
	window.open(url,_target)
}*/

function winSkip(url,_target){ 
//	window.frames[_target].location=url;
//	window.location.href=url;
	window.open(url,_target);
}
 
		
function addItem(leftope,rightope){
    var leftobj =leftope;// document.getElementById(leftope);
 	var optionLeftLen = leftobj.options.length;
	 var rightObj =rightope;// document.getElementById(rightope);
	for(var i = optionLeftLen-1; i >= 0; --i){
		if(leftobj.options(i).selected){
			var value = leftobj.options(i).value;
			if(checkOption(rightObj,value) == true){
				var addOption = document.createElement('OPTION');
				addOption.text = leftobj.options(i).text;
				addOption.value = leftobj.options(i).value;
				rightObj.options.add(addOption);
			}
		}
	} 
} 

	function checkOption(targetObj,value){
			var optionTargetLen = targetObj.options.length;
			
			if(optionTargetLen == 0){
				return true ;
			}
			else{
				for(var i = optionTargetLen-1; i >= 0; --i){
					if(value == targetObj.options(i).value){
						return false;
					}
				}
			}
			return true;
		}
		
function delItem(leftope,rightope){
	 var rightObj =rightope;// document.getElementById(rightope);
	 var optionRightLen = rightObj.options.length;
			 for(var i = optionRightLen-1; i >= 0; --i){
				if( rightObj.options(i).selected){
					 rightObj.options.remove(i);
				}
			 }
}

//remove all options
function removeItems(ope){ 
	 var opeLen = ope.options.length;
			 for(var i = opeLen-1; i >= 0; --i){ 
			 	if( ope.options(i).selected){
					 ope.options.remove(i);
				} 
				 
			 }
}


function checkAll(status){
               alert(status);
               for (var i=0;i < document.forms[0].elements.length; i++){
				var e = document.forms[0].elements[i];
				if (e.name=="checkBoxId")
					document.forms[0].elements[i].checked=status;
			}
			
		}
		
function switchAll(_chk,_check) { 
	var len = _check.length; 
	if(len>1){
	for (var j = 0; j <= len -1; j++) {
		var tmpbox = _check[j]; 
	 	if(_chk.checked){
	 		tmpbox.checked = true;
	 	}else tmpbox.checked = false;
// 		tmpbox.checked = !tmpbox.checked;
   }
   }else _check.checked = !_check.checked;
}


function formatDateTime(value) {
	var obj = new Date(value);
	var year=obj.getFullYear();
	var month=obj.getMonth()+1;
	if(month<10)
		month = '0' + month;
	var date=obj.getDate();
	if(date<10)
		date = '0' + date;
	var hour=obj.getHours();
	if(hour<10)
		hour = '0' + hour;
	var minute=obj.getMinutes();
	if(minute<10)
		minute = '0' + minute;
	//var second=obj.getSeconds();
	document.write(year+"-"+month+"-"+date + ' ' + hour + ':' + minute);
}

function checkLen(_source,_target){
	var obj_s = document.getElementById(_source);
	var obj_t = document.getElementById(_target);
	if(obj_s != null && obj_t != null){
		var _value = obj_s.value ;
		obj_t.innerText = "("+_value.length + ")";
	}
}

//??????????????????????
function refreshParent(){
	 	var url = window.opener.location.href;
	 	var idx1 = url.indexOf("#");
	 
		if(idx1>-1){
			url = url.substring(0,idx1);
		}
	 	window.opener.location.href= url; 
}
 
function strLen(obj){  
	var str = obj.value; 
	var len = 0;   
    for (var i=0;i<str.length;i++)   
    {   
        if (str.charCodeAt(i)>255) len+=2; else len++;   
    }  
    
     
    return len;   
	
	 
}
 

function f_check_mobile(obj,msg){   
	if(obj.value==""){
		alert(msg);
		obj.focus();
	 	return false;
	} 
	var myReg = /(^[0-9][0-9][0-9]{9}$)|(^0[0-9][0-9][0-9]{9}$)/;    
    if(myReg.test( obj.value )) return true;     
    alert(msg);   
    obj.value="";
    return false;      
}
function isNumber(obj,msg){   
	if(obj.value==""){
		alert(msg);
		obj.focus();
	 	return false;
	} 
	var myReg = /(^[0-9]*$)/;    
    if(myReg.test( obj.value )) return true;     
    alert(msg);   
    obj.value="";
    return false;      
}

function f_check_letter(obj,msg)   
{         
    if (/^[A-Za-z0-9]+$/.test( obj.value ))    
    {   
       return true;   
    }    
    alert(msg);   
    return false;   
}   

	function checkAll(status,chkName){
               //alert(status);
               for (var i=0;i < document.forms[0].elements.length; i++){
				var e = document.forms[0].elements[i];
				//alert(e.name);
				if (e.name=="checkbox2")
					document.forms[0].elements[i].checked=status;
			}
			
		}
		
//add by ewen
//eg: <input type="text" onkeypress="return intBox();" />
function intBox() {
	if(event.keyCode < 48 || event.keyCode > 58) {
		return false;
	}
  return true;
}
function intBoxDate() {
    //alert("event.keyCod="+event.keyCode);
    if(event.keyCode!=45){
	    if(event.keyCode < 48 || event.keyCode > 58) {
			return false;
		}
	}
	return true;
}

//eg: <input type="text" onkeypress="return intBox(11);" />
function intBox(maxLen) {
	if(event.keyCode < 48 || event.keyCode > 58) {
		return false;
	}
	if (maxLen > 0 && event.srcElement.value.length >= maxLen) {
		return false;
	}
	return true;
}
//eg: <input type="text" onkeypress="return asciiBox();" />
function asciiBox() {
	if(event.charCode > 127) {
		event.returnValue = false;
	}
	event.returnValue = true;
}
//eg: <input type="text" onkeypress="return asciiBox(12);" />
function asciiBox(maxLen) {
	if(event.charCode > 127) {
		return false;
	}
	if (maxLen > 0 && event.srcElement.value.length >= maxLen) {
		return false;
	}
	return true;
}
//eg: <input type="text" onkeypress="return numLetter();" />
function numLetter(){
 if (! ((event.keyCode >= 48 && event.keyCode <= 57)||(event.keyCode >= 65 && event.keyCode <= 90)||(event.keyCode >= 97 && event.keyCode <= 122))) 
 {
	return false;
  }
   return true;
}

//eg: <input type="text" onkeypress="return specialLetter();" />
function specialLetter(){
//alert("objValue"+obj.value+"::"+obj.value.length);
//var reg=/[^%&',;=?$\x22]+/;
//alert(reg.test(obj.value));
//if(obj.value.length==0)return false;
//if(!reg.test(obj.value)){
//obj.value="";
//alert(event.keyCode);
if(event.keyCode==39)
return false;

return true;
}

//eg: <input type="text" onkeyup="javascript:isNotChinese(this);" />
function isNotChinese(objVal){
//objVal.value=objVal.value.replace(/[\u4e00-\u9fa5]/g,'')
var reg=/[\u4e00-\u9fa5]/g;
//alert(objVal.value);
//alert(reg.test(objVal.value));
if(reg.test(objVal.value)){
objVal.value="";
return false;
}
//return true;
}

//测试特殊字符的javascript函数
//demo
/*
    //将需要验证的ID传入数组
	var propertyArray = new Array();
	propertyArray.push("flightNum");
	propertyArray.push("flightDate");
	//把验证数组传入验证特殊字符函数
	var result=checkSpecialInput(propertyArray);
	if(result==true){
	    //form 提交
	    vipServiceSheetForm.submit();
	     
	}else{
	  //如果验证不通过，报错！
	    alert(result);
	}
*/
function checkSpecialInput(propertyArray){
	
	var lengthVal=propertyArray.length;
	var errorVal="查询条件不能包括特殊字符:%&',;=?$x22+!~\/{}@，请重新输入！";
	var reg=/[%&',;=?$\x22+!~\\\/\{\}@]+/;
	//alert("lengthVal="+lengthVal);
		for(var i=0;i<lengthVal;i++){
		  //alert(i)
		  var elemReg=false;
		  var elemId=propertyArray[i];
		  var elemTxt=document.getElementById(elemId);
		  //alert(elemTxt.value);
		  if(elemTxt!=null&&elemTxt.value.length>0)elemReg=reg.test(elemTxt.value);
		  if(elemReg==false){
		     //alert("elemReg="+elemReg);
		     if(i!=5)continue;
		     return true;
		  }else {
		    return errorVal;
		  }
	    }
}

//for time compaire
function timeCheck(objId){
       //alert(objId);
	   var msgShowForTimeCheck=document.getElementById("msgShowForTimeCheck");
	   var errorTimeMsgShow=document.getElementById("errorTimeMsgShow");
	   var etdTimeShowSpan=document.getElementById("etdTimeShowSpan");
	   var etd=document.getElementById("etd");
	   var ObjTime=document.getElementById(objId);
	   var messagesPresentTrId=document.getElementById("messagesPresentTrId");
	   var messageShowTrIdTd=document.getElementById("messageShowTrId");
	   
	   var re=/-/g; 
	   if(etd!=null)
	   var etdStr=etd.value.replace(re,"/").substring(0,16);
	   if(ObjTime!=null)
	   var ObjTimeStr=ObjTime.value.replace(re,"/").substring(0,16);
	   var etdDateTime=new Date(etdStr);
	   var ObjTimeDateTime=new Date(ObjTimeStr);
	   //alert(etdStr+"::"+ObjTime.value);
	   var df=(etdDateTime.getTime()-ObjTimeDateTime.getTime())/1000/60;
	   //alert(df);
	   if(ObjTimeStr=="")df=1;
	   if(df>0)return true;
	   
	   if(msgShowForTimeCheck!=null)
	   msgShowForTimeCheck.style.display="";
	   if(errorTimeMsgShow!=null)
	   errorTimeMsgShow.style.display="";
	   if(etdTimeShowSpan!=null)
	   etdTimeShowSpan.innerText=etd.value.substring(0,16);
	   if(messagesPresentTrId!=null)
	   messagesPresentTrId.style.display="none";
	   if(messageShowTrIdTd!=null)
	   messageShowTrIdTd.style.display="none";
	   return false;
	}

//array remove all
/*Array.prototype.removeAll = function() { 
	while(this.length > 0) this.pop();  
} */

function $(s){return document.getElementById(s);}